package cn.jc.springframework.aop.framework.adapter;

import cn.hutool.core.lang.Assert;
import cn.jc.springframework.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @Description:
 * @author: JC
 * @date: 2023/4/9 15:41
 */
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {


    private MethodBeforeAdvice advice; //对应的是之前增强的详细信息

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice){
        Assert.notNull(advice, "Advice must not be null");
        this.advice = advice;
    }

    public MethodBeforeAdviceInterceptor() {
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        this.advice.before(mi.getMethod(), mi.getArguments(),mi.getThis());
        return mi.proceed();
    }

    public void setAdvice(MethodBeforeAdvice advice) {
        this.advice = advice;
    }
}
